package com.mybed.crm.controller;

import com.mybed.crm.pojo.vo.IndexVo;
import com.mybed.crm.pojo.vo.IndexStatisticsVo;
import com.mybed.crm.result.Result;
import com.mybed.crm.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/index")
@Slf4j
public class IndexController {

    @Autowired
    private ReportService reportService;

    /**
     * 获取基础信息
     */
    @GetMapping("/getBaseInfo")
    public Result getBaseInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                              @RequestParam("endCreateTime") String endCreateTime){
        return Result.success(reportService.getBaseInfo(beginCreateTime, endCreateTime));
    }

    /**
     * 商机转化龙虎榜
     */
    @GetMapping("/businessChangeStatistics")
    public Result businessChangeStatistics(IndexStatisticsVo request){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        request.setBeginCreateTime(request.getBeginCreateTime()+" 00:00:00");
        request.setEndCreateTime(request.getEndCreateTime()+" 23:59:59");
        List<Map<String,Object>> list= reportService.businessChangeStatisticsForIndex(request);
        return Result.success(list);
    }

    /**
     * 线索转化龙虎榜
     */
    @GetMapping("/salesStatistic")
    public Result salesStatistic (IndexStatisticsVo request){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        request.setBeginCreateTime(request.getBeginCreateTime()+" 00:00:00");
        request.setEndCreateTime(request.getEndCreateTime()+" 23:59:59");
        List<Map<String, Object>> list = reportService.salesChangeStatisticsForIndex(request);
        return Result.success(list);
    }
    @GetMapping
    public Result<IndexVo> getIndexInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                        @RequestParam("endCreateTime") String endCreateTime,
                                        @RequestParam Integer deptId){
        return Result.success(reportService.getIndexInfo(beginCreateTime, endCreateTime));
    }

}
